﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SinsenWeb.Models;
using SinsenWeb.Models.ViewDataTypes;


namespace SinsenWeb.Views.Members
{
    public partial class List : ViewPageBase<List<Member>>
    {
        private Dictionary<Models.Instrument, List<Member>> _memberGroups;
        public Dictionary<Models.Instrument,List<Member>> MemberGroups
        {
            get
            {
                if (_memberGroups == null)
                {
                    _memberGroups = GetMemberGroups(Model);
                }
                return _memberGroups;
            }
        }

        private Dictionary<Models.Instrument, List<Member>> GetMemberGroups(List<Member> members)
        {
            var groups = new Dictionary<Models.Instrument, List<Member>>();
            foreach(var member in members)
            {
                if(!groups.ContainsKey(member.Instrument))
                {
                    groups[member.Instrument] = new List<Member>();
                }
                groups[member.Instrument].Add(member);
            }
            return groups;
        }
    }
}
